/**
 * @file http.hpp
 * @brief HTTP 模块
 */
#pragma once
#include <crane/defs.hpp>
#include <crane/core/error.hpp>

CRANE_NS_BEGIN
namespace http {

class HttpHeader {};

class HttpHeaders {};

struct HttpClientAsyncChannel {
    using Ptr = std::unique_ptr<HttpClientAsyncChannel>;
};

struct HttpIoCreateChannelCallback {
    virtual ~HttpIoCreateChannelCallback() = default;
    virtual void onCreateChannel(HttpClientAsyncChannel::Ptr channel, Error & err) = 0;
};



struct HttpAsyncIoAdapter {
public:
    virtual ~HttpAsyncIoAdapter() = default;

    virtual Error createChannel(const String &host, const String & port, HttpIoCreateChannelCallback * handler) = 0;
    virtual Error createSSLChannel(const String &host, const String & port, HttpIoCreateChannelCallback * handler) = 0;
};

struct HttpClientCallback {
    virtual ~HttpClientCallback() = default;
};

class HttpAsyncClientImpl;

class CRANE_API HttpAsyncClient {
public:
    HttpAsyncClient();

    Error get(const std::string & url, HttpHeaders headers, HttpClientCallback * callback);
    Error post(const std::string & url, HttpHeaders headers, HttpClientCallback * callback);
    Error put(const std::string & url, HttpHeaders headers, HttpClientCallback * callback);
    Error del(const std::string & url, HttpHeaders headers, HttpClientCallback * callback);
    Error head(const std::string & url, HttpHeaders headers, HttpClientCallback * callback);
    Error options(const std::string & url, HttpHeaders headers, HttpClientCallback * callback);
    Error patch(const std::string & url, HttpHeaders headers, HttpClientCallback * callback);
    Error trace(const std::string & url, HttpHeaders headers, HttpClientCallback * callback);
private:
    std::shared_ptr<HttpAsyncClientImpl> m_impl;
}; // HttpAsyncClient

} // http
CRANE_NS_END
